package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.DataCollectionMapper;
import com.zhentao.pojo.DataCollection;
import com.zhentao.service.DataCollectionService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author 李佳隆
* @description 针对表【data_collection(海关数据采集主表：存储所有采集方式的原始数据)】的数据库操作Service实现
* @createDate 2025-08-27 09:50:25
*/
@Service
public class DataCollectionServiceImpl extends ServiceImpl<DataCollectionMapper, DataCollection>
    implements DataCollectionService{

    @Override
    public List<DataCollection> getPageList(Integer page, Integer size, Map<String, Object> queryParams) {
        // 创建分页对象
        Page<DataCollection> pageObj = new Page<>(page, size);
        
        // 构建查询条件
        QueryWrapper<DataCollection> queryWrapper = new QueryWrapper<>();
        
        if (queryParams != null) {
            // 状态条件
            if (queryParams.get("status") != null) {
                queryWrapper.eq("status", queryParams.get("status"));
            }
            
            // 关区条件
            if (queryParams.get("customsArea") != null) {
                queryWrapper.eq("customs_area", queryParams.get("customsArea"));
            }
            
            // 数据类型条件
            if (queryParams.get("dataType") != null) {
                queryWrapper.eq("data_type", queryParams.get("dataType"));
            }
            
            // 用户ID条件
            if (queryParams.get("userId") != null) {
                queryWrapper.eq("user_id", queryParams.get("userId"));
            }
        }
        
        // 按创建时间倒序排列
        queryWrapper.orderByDesc("create_time");
        
        // 执行分页查询
        IPage<DataCollection> result = this.page(pageObj, queryWrapper);
        
        return result.getRecords();
    }

}




